﻿using LeastSquaresTechnique.Models;
namespace LeastSquaresTechnique
{
    internal class Program
    {
        /// <summary>
        /// 通过最小二乘法进行计算
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //从数据文件中读取
            var model = new RegressionModel();
            model.X = MyFunctions.ListReadTxt(@$"{System.Environment.CurrentDirectory}\date\year.txt");
            model.Y = MyFunctions.ListReadTxt(@$"{System.Environment.CurrentDirectory}\date\Gdp.txt");
            //计算参数
            model.Compute();
            //预测
            var gdp=model.Forecast(2021);
            Console.WriteLine($"预测2021年的GDP为{gdp.ToString("##.##")}万亿美元");
            //计算精度
            double fact = 17.73;
            double presicion = -(gdp - fact) / fact;
            Console.WriteLine($"预测精度为{presicion}");
        }
    }
}